#ifndef BODYENTITY_H
#define BODYENTITY_H

#include "Common/Common.h"
#include "EditorCore/IProvider.h"
#include "EditorCore/Entity.h"
#include "Entities/CircleEntity.h"
#include "Entities/PolygonEntity.h"
#include "Entities/BodyEntity.h"

class BodyEntity : public editor_core::Entity, public editor_core::IProvider<BodyEntity*>
{
public:
	BodyEntity( float mass, float inertia, float friction, float restitution );
	virtual ~BodyEntity();

	inline float GetMass() const { return m_mass; }
	inline void SetMass( float mass ) { m_mass = mass; }

	inline float GetInertia() const { return m_inertia; }
	inline void SetInertia( float inertia ) { m_inertia = inertia; }

	inline float GetFriction() const { return m_friction; }
	inline void SetFriction( float friction ) { m_friction = friction; }

	inline float GetRestitution() const { return m_restitution;; }
	inline void SetRestitution( float restitution ) { m_restitution = restitution; }

	void AddCircle( CircleEntity* circle );
	void RemoveCircle( CircleEntity* circle );
	void GetCircles( cmn::ICollection<CircleEntity*>& circles ) const;

	void AddPolygon( PolygonEntity* polygon );
	void RemovePolygon( PolygonEntity* polygon );
	void GetPolygons( cmn::ICollection<PolygonEntity*>& polygons ) const;

	virtual inline BodyEntity* GetEntity() { return this; }

	virtual void Tick();

	virtual inline cmn::Vec2 Move( const cmn::Vec2& vector ) { return cmn::Vec2::Zero(); }

	virtual void Delete();
	virtual void Undelete();

	virtual bool Contains( const cmn::Vec2& point ) const;

	virtual void GetChildren( cmn::ICollection<IEntity*>& children ) const;
	virtual void GetParents( cmn::ICollection<IEntity*>& parents ) const;

	virtual void GetProperties( cmn::ICollection<editor_core::Property>& properties ) const;
	virtual bool TryUpdateProperty( editor_core::Property& property ) const;
	virtual bool TryUpdateFromProperty( const editor_core::Property& property );

protected:
	virtual void DrawInner( drawing::IDrawer* drawer );

private:
	float m_mass;
	float m_inertia;
	float m_friction;
	float m_restitution;

	cmn::Vector<CircleEntity*> m_circles;
	cmn::Vector<PolygonEntity*> m_polygons;
};

#endif
